﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Twi.COMMON.WCF
{
    public static class StringExtensions
    {
        public static void SplitInto(this string me, char separator, out string part1, out string part2) 
        {
            var array = me.Split(separator);
            part1 = array[0];
            part2 = array[1];
        } 

        public static string MaskWithWildcard(this string me) 
        {
            if (me.Contains('_') || me.Contains('%'))
            {
                return me;
            }
            else
            {
                return string.Format("%{0}%", me);
            }
        }

        /// <summary>
        /// 如果字符窜不为空, 就返回格式化结果, 空就返回空
        /// </summary>
        /// <param name="me"></param>
        /// <param name="format"></param>
        /// <returns></returns>
        public static string FormatNotEmpty(this string me, string format) 
        {
            if (me.Trim() == "") 
            {
                return me;
            }
            return string.Format(format, me.Trim());
        }

        public static string SubstringFromEnd(this string me, int length)
        {
            if (me == "")
                return "";
            return me.Substring(me.Length - length, length);
        }
    }
}
